<?php
// $Id: RadioSetInput.php 27 2010-11-16 12:49:54Z mjohnson60@gmail.com $


/**
 * Enter description here ...
 * 
 * @author Mark Phillip Johnson
 * @version 1.0
 * @copyright Copyright (c) 2010, markjohnson
 * @license http://www.gnu.org/licenses/gpl.html The GNU General Public License v3.0
 *
 */
class RadioSetInput extends FormElement
{

	/**
	 * __construct()
	 * 
	 * Enter description here ...
	 * 
	 */
	function __construct($name, $value = NULL, $id = NULL, $parent = NULL, $attributes = array(), $title = '', $radios = array())
	{
		$this->type = 'radioset';
		$this->title = $title;
		$this->children = $radios;
		
		foreach ($this->children as $radio_name => $radio)
		{
			if (is_array($radio))
			{
				$this->children[$radio_name] = new RadioInput($name, $radio['#value'], (empty($radio['#id']) ? $radio_name : $radio['#id']), $this, (empty($radio['#attributes']) ? array() : $radio['#attributes']), (empty($radio['#title']) ? '' : $radio['#title']), (empty($radio['#selected']) ? FALSE : TRUE));
				$return_value = (empty($radio['#return_value']) ? '' : $radio['#return_value']);
				$this->children[$radio_name]->return_value = $return_value;
			}
			else if (is_object($radio))
			{
				$this->children[$radio_name] = $radio;
			}
		}
		
		if (is_array($value))
		{
			parent::__construct($value, $name);
		}
		else
		{
			parent::__construct(NULL, $name, $value, $id, $parent, $attributes);
		}
	}

	/* 
	 * @see FormElement::_compile()
	 */
	public function _compile()
	{
		return $this->render();
	}

	/* 
	 * @see FormElement::render()
	 */
	public function render()
	{
		return parent::render($this->content);
	}
}